<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
  </style>
</head>

<body>
  <canvas id="canvas"></canvas>
</body>
<script>
  
  const canvas = document.getElementById('canvas');
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  const gl = canvas.getContext('webgl'); // 获取webgl类型的上下文
  gl.clearColor(0, 0, 0, 1);
  console.log(gl.COLOR_BUFFER_BIT);
  console.log(gl);
  gl.clear(gl.COLOR_BUFFER_BIT);

  // css颜色转为webgl颜色
  // const rgbaCSS = "rgba(255,0,0,1)";
  // const reg = RegExp(/\((.*)\)/);
  // const rgbaStr = reg.exec(rgbaCSS)[1];
  // const rgb = rgbaStr.split(",").map((ele) => parseInt(ele));
  // const r = rgb[0] / 255;
  // const g = rgb[1] / 255;
  // const b = rgb[2] / 255;
  // const a = rgb[3];

  // gl.clearColor(r, g, b, a);
  // gl.clear(gl.COLOR_BUFFER_BIT);
</script>

</html>